package priv.pront.code.mati.province;

import java.util.Scanner;

/**
 * @Description:
 * @Author: pront
 * @Time:2023-11-16 18:03
 */
public class MC0221 {

    static int n;
    static int[] la, ra;
    static int ans1, ans2 = 0;

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        n = scanner.nextInt();
        la = new int[n];
        ra = new int[n];
        for (int i = 0; i < n; i++) {
            la[i] = scanner.nextInt();
            ra[i] = scanner.nextInt();
        }
        int[] presum = new int[n];
        presum[0] = ra[0] - la[0];
        ans1 = presum[0];
        for (int i = 1; i < n; i++) {
            if (la[i] <= ra[i - 1]) {
                presum[i] = presum[i - 1] + ra[i] - ra[i - 1];
            } else {
                presum[i] = ra[i] - la[i];
            }
            ans1 = Math.max(ans1, presum[i]);
        }

        for (int i = 1; i < n; i++) {
            if (la[i] > ra[i - 1]) {
                int sub = la[i] - ra[i - 1];
                ans2 = Math.max(ans2, sub);
            }
        }
        System.out.println(ans1 + " " + ans2);
    }
}
